package com.usian.article.controller;

import com.usian.api.article.ApArticleControllerApi;
import com.usian.article.service.ApArticleService;
import com.usian.model.article.dto.ArticleHomeDto;
import com.usian.model.article.dto.ArticleInfoDto;
import com.usian.model.article.pojos.ApArticle;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description:
 * @Auther:ASS
 * @Date:2023/2/22 11:18
 */
@RestController
@RequestMapping("/api/v1/article")
public class ApArticleController implements ApArticleControllerApi {

    @Autowired
    private ApArticleService apArticleService;



    /*
    * admin远程调用文章的主表
    *
    * */
    @Override
    @RequestMapping("/saveApArticle")
    public ApArticle saveApArticle(@RequestBody ApArticle apArticle) {
        return apArticleService.saveApArticle(apArticle);
    }


    /**
     * 加载首页文章
     *
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/load")
    public ResponseResult load(@RequestBody ArticleHomeDto dto) {
        return apArticleService.loadList((short) 1,dto);
    }

    /**
     * 加载更多 上拉加载更多
     *
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/loadmore")
    public ResponseResult loadMore(@RequestBody ArticleHomeDto dto) {
        return apArticleService.loadList((short)1,dto);
    }



    /**
     * 加载最新 下拉加载最新
     *
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/loadnew")
    public ResponseResult loadNew(@RequestBody ArticleHomeDto dto) {
        return apArticleService.loadList((short)2,dto);
    }




    /**
     * 加载文章详情
     *
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/load_article_info")
    public ResponseResult loadArticleInfo(@RequestBody ArticleInfoDto dto) {

        return apArticleService.loadArticleInfo(dto);
    }


    /**
     * 查询文章关系接口
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/load_article_behavior")
    public ResponseResult loadArticleBehavior(@RequestBody ArticleInfoDto dto) {
        return apArticleService.loadArticleBehavior(dto);
    }


    /**
     * search 远程获取发布后的文章
     * @return
     */
    @Override
    @PostMapping("/findArticle")
    public List<ApArticle> findArticle() {
        return apArticleService.list();
    }


}
